home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
-
- extern char *malloc(), *realloc();
- extern char *sys_errlist[];
- extern int sys_nerr, errno;
- void MyError();
-
- void MySysError (s, file)
- char *s, *file;
- {
- fprintf(stderr, "%s %s", s, file);
- if (errno < sys_nerr)
- fprintf(stderr, "%s", sys_errlist[errno]);
- fprintf(stderr, "\n");
- fflush(stderr);
- exit(1);
- }
-
- FILE *MyOpen (file, mode)
- char *file, *mode;
- {
- FILE *fd;
-
- if ((fd = fopen(file, mode)) == NULL)
- MyError("Unable to open", file);
- return(fd);
- }
-
- void MyClose (fd)
- FILE *fd;
- {
- if (fclose(fd) == EOF)
- perror("Warning: ");
- }
-
- void myread (p, s, n, fd)
- char *p;
- int s, n;
- FILE *fd;
- {
- if (fread(p, s, n, fd) != n)
- MySysError("Unable to read", "");
- }
-
- void mywrite (p, s, n, fd)
- char *p;
- int s, n;
- FILE *fd;
- {
- if (fwrite(p, s, n, fd) != n)
- MySysError("Unable to write", "");
- }
-
- int MyFileLen (fd)
- FILE *fd;
- {
- long old;
- long n;
-
- if ((old = ftell(fd)) == -1)
- MySysError("Unable to ftell", "");
- if (fseek(fd, (long)0, 2) == -1)
- MySysError("Unable to seek", "");
- if ((n = ftell(fd)) == -1)
- MySysError("Unable to ftell", "");
- if (fseek(fd, old, 0) == -1)
- MySysError("Unable to seek", "");
- return((int)(n - old));
- }
-
- void MySeek (fd, off, ptr)
- FILE *fd;
- long off;
- {
- if (fseek(fd, off, ptr) == -1)
- MySysError("Unable to seek", "");
- }
-
- char *mymalloc (n)
- unsigned n;
- {
- char *p;
-
- if ((p = malloc(n)) == NULL)
- MyError("Out of space", "");
- return(p);
- }
-
- char *myrealloc (p, n)
- char *p;
- unsigned n;
- {
- char *np;
-
- if ((np = realloc(p, n)) == NULL)
- MyError("Out of space", "");
- return(np);
- }
-
- void MyError (s, t)
- char *s, *t;
- {
- fprintf(stderr, "%s %s\n", s, t);
- fflush(stderr);
- exit(1);
- }
-
-